title = "分类详情页"
url = '/:slug|[a-z0-9\-]+-c-\d+.html$'
title = '分类详情页模板'
layout = 'default'
==
use Jason\Ccshop\Controllers\Filters;
use Jason\Ccshop\Controllers\Categories;
use Jason\Ccshop\Models\Category;
use Jason\Ccshop\Models\Product;
use Jason\Ccshop\Models\Promotion;
use Jason\Ccshop\Components\Catalog;
function onStart(){
$slugArr = explode('-', str_replace('.html','', $this->param('slug')));
$slug = str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), $this->param('slug'));
$id = array_pop($slugArr);
array_pop($slugArr);
$condition = ['id' => $id];

$this['paramKey'] = join('-', $slugArr);
$categoryModel = Category::where('id', $id)->first();

$this['currentUrl'] = str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), substr(request()->getRequestUri(),1));
$this['sortFlag'] = $slugArr[0];

if(!$categoryModel) {
return redirect('/404');
}
$this['category'] = $categoryModel;

$pids = get('id_sort')?get('id_sort'):null;
$pageNumber = get('page')?get('page'):1;

if(!empty($pids)){
Cookie::queue('idssort',$pids);
Cookie::queue('cid',$id);
Cookie::queue('pagenumber',$pageNumber);
}else{
$pageNumber = Cookie::get('pagenumber');
$cid = Cookie::get('cid');
$currentPage = get('page')?get('page'):1;
if($currentPage==$pageNumber && $id==$cid){
$pids = Cookie::get('idssort');
}
}

if (!empty($pids)) {
$pida = explode(',',$pids);
$pd = Product::InStock()->whereIn('id',$pida)->get();
$this['adproducts'] = $pd;
$this['pida'] = $pida;
}

if ($this['paramKey'] != $categoryModel['slug']) {
$paramKey = explode('-',$this['paramKey']);
$orderArr = Filters::parseFilterKeyParams($paramKey[0]);
if (count($orderArr) == 2) {
$order = [$orderArr[0] => $orderArr[1]];
}
}

$this['order'] = isset($order) ? $order : ['sort' => 'desc'];
$this['products'] = App::make('Jason\Ccshop\Controllers\Products')->getCategoryProducts($categoryModel->id, $this['order']);

   //促销产品
    $promotionNow = Promotion::where('name', 'christmas_now')->first();
    $this['collectPromotions'] = [];
    $now = time();
    if(strtotime($promotionNow->from_date) < $now && strtotime($promotionNow->to_date) > $now){
	    $promotions = (new Catalog)->getProductsByPromotionName('christmas_now'); 
	    $collectPromotions = [];
	    foreach($promotions as $promotion){
	       $collectPromotions[$promotion['id']] = true;
	    }
	    $this['collectPromotions'] = $collectPromotions;
    }

}
==

{% put page_title %}{{ category.page_title }}{% endput %}
{% put meta_keywords %}{{ category.meta_keywords }}{% endput %}
{% put meta_description %}{{ category.meta_description }}{% endput %}

{% for key, product in products.data %}
  {% put google_tag_params %}
  var google_tag_params = {
    ecomm_prodid: "{{product.id}}",
    ecomm_pagetype: "category",
    ecomm_totalvalue: {{product.price|ratePrice}}
  };
  {% endput %}
{% endfor %}
<div class="category_content">
		<!-- breadcrumbs -->
		{% partial 'common/breadCrumb' category=category %}
		<!-- breadcrumbs end -->
		<div class="categoryCont">
			<div class="container">
				{% partial 'catalog/category-sidebar' products=products %}


				<div class="fr rightBox">
					<!--推送广告位 start-->
					{% partial 'catalog/ad-products' adproducts=adproducts %}
					<!--推送广告位 end-->
					<div class="catg_rightBoxTop boxSizing">
						<div class="fl">
							<button class="fiveShow" dataClass="fiveShow"><i class="fa fa-th"></i></button>
							<button class="threeShow active" dataClass="threeShow"><i class="fa fa-th-large"></i></button>
						</div>
						{% partial 'catalog/category-paging' %}
						
					</div>
					{% partial 'catalog/list-toolbar' %}

					<div class="catg_productBox">
						<ul class="catg_product ">
							{% for product in products.data %}
								<li class="catgItem ">
									<a href="{{ product.url }}" title="{{ product.name }}">
									

										<div class="catgItem_image ">
											<img  class="lazy " data-original="{{ product.f_thumb }}" alt="{{ product.name }}" width="100%">
											{% if product.saled > 500 %}
											<span class="hotSale sale_"><img src="{{ 'assets/img/hotSale.png'|theme }}" alt=""></span>
											{% endif %}

											{% if product.labels == "newest" %}
											<span class="newSale sale_"><img src="{{ 'assets/img/newSale.png'|theme }}" alt=""></span>
											{% endif %}
										</div>
										<div class="catgItem_data">
											<p class="omit"></p>
											<p class="omit">{{ product.name }}</p>
											{% if collectPromotions[product.id]%}
											<p class="omit">{{ product.id|getDbPrice|formatPrice }} 税込</p>
											{% else %}
											<p class="omit">{{ product.price|formatPrice }} 税込</p>
											{% endif %}
											<p class="omit">
												<span class="reviewStar size2 star{{ product.rating }}"></span>
												{% if product.reviews_total %}
												<a href="{{ product.url }}?rel={{ list }}#reviews" class="reviewsShow">レビュー / <b>{{ product.reviews_total }}</b> 件</a>
												{% endif %}
											</p>
										</div>
									</a>
									
								</li>
							{% endfor %}

						</ul>	
					</div>
					<div class="catg_rightBoxTop boxSizing">
						{% partial 'catalog/category-paging' %}
					</div>
				</div>
			</div>
		</div>
	</div>
